
package com.mengmeizi;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.net.Uri;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.umeng.analytics.MobclickAgent;

public class ActAbout extends Activity implements OnClickListener {

    private SoftApplication application;

    private ImageView imvTitle;

    private LinearLayout llySina;

    private LinearLayout llyTencent;

    private TextView txvVersion;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_about);

        application = (SoftApplication) getApplication();

        application.addActivity(this);

        imvTitle = (ImageView) findViewById(R.id.imvTitle);
        imvTitle.setOnClickListener(this);

        String version = "V1.0.0";

        try {
            PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), 0);
            version = info.versionName;
        } catch (Exception e) {
            e.printStackTrace();
        }

        txvVersion = (TextView) findViewById(R.id.txvVersion);
        txvVersion.setText("V" + version);

        llySina = (LinearLayout) findViewById(R.id.llySina);
        llySina.setOnClickListener(this);
        llyTencent = (LinearLayout) findViewById(R.id.llyTencent);
        llyTencent.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (v instanceof ImageView) {
            if (v == imvTitle) {
                Intent intent = new Intent(this, ActMore.class);
                startActivity(intent);
                this.finish();
            }
        } else if (v instanceof LinearLayout) {
            Uri uri = null;
            if (v == llySina) {
                uri = Uri.parse(getString(R.string.sinaAddress));
            } else if (v == llyTencent) {
                uri = Uri.parse(getString(R.string.tencentAddress));
            }
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            intent.setClassName("com.android.browser", "com.android.browser.BrowserActivity");
            startActivity(intent);
        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            Intent intent = new Intent(this, ActMore.class);
            startActivity(intent);
            this.finish();
        }
        return super.onKeyDown(keyCode, event);
    }

    public void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);

    }

    public void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }

}
